import unittest
import jsonschema
from api.py01_IhrmLoginApi import IhrmLoginApi
from common.py01_IhrmAssertUtil import common_assert
from parameterized import parameterized
from common.py02_JsonUtil import read_Login_data
from config import BASE_PATH


class IhrmLoginTest(unittest.TestCase):

    # 登录
    @parameterized.expand(read_Login_data(path_file=BASE_PATH + "/data/ihrm_login.json"))
    def test_Login(self, desp, login_data, status_code, success, code, msg):
        print("登录用例：", desp)
        # 登录
        resp = IhrmLoginApi.ihrmLoginSucess(json_data=login_data)
        print(resp.json())
        # 断言
        # common_assert(self, resp, status_code, success, code, msg)

        #全量字段校验 替换 断言
        schema = {
            "type": "object",
            "properties": {
                "success": {"const": success},
                "code": {"const": code},
                "message": {"pattern": msg},
                # "data": {"type": "string"}
            },
            "required": ["success", "code", "message", "data"]
        }

        jsonschema.validate(resp.json(), schema)


"""

    # 手机号未注册
    def test02_tel_err(self):
        # 登录数据
        Login_data = {"mobile": "1380056625", "password": "929itheima.CN032@.20250416"}
        # 登录
        resp = IhrmLoginApi.ihrmLoginSucess(json_data=Login_data)
        # 断言
        common_assert(self, 200, False, 20001, "用户名或密码错误", resp)

    # 密码错误
    def test03_pwd_err(self):
        # 登录数据
        Login_data = {"mobile": "13800000002", "password": "929itheima.CN032@.2025041"}
        # 登录
        resp = IhrmLoginApi.ihrmLoginSucess(json_data=Login_data)
        # 断言
        common_assert(self, 200, False, 20001, "用户名或密码错误", resp)

    # 手机号为空
    def test04_telEmpty_err(self):
        # 登录数据
        Login_data = {"mobile": "", "password": "929itheima.CN032@.2025041"}
        # 登录
        resp = IhrmLoginApi.ihrmLoginSucess(json_data=Login_data)
        # 断言
        common_assert(self, 200, False, 20001, "用户名或密码错误", resp)

    # 多参
    def test05_more_param(self):
        # 登录数据
        Login_data = {"mobile": "13800000002", "password": "929itheima.CN032@.20250416", "abc": "123"}
        # 登录
        resp = IhrmLoginApi.ihrmLoginSucess(json_data=Login_data)
        # 断言
        common_assert(self, 200, True, 10000, "操作成功", resp)

    # 无参
    def test06_None_param(self):
        # 登录数据
        Login_data = {}
        # 登录
        resp = IhrmLoginApi.ihrmLoginSucess(json_data=Login_data)

        # 断言
        common_assert(self, 200, False, 20001, "用户名或密码错误", resp)

"""
